
function myAll(...promises) {
    console.log(promises);
    return new Promise((resolve, reject) => {
        let count = 0;
        let len = promises.length;
        let ans = [];
        for (let i = 0; i < len; i++) {
            promises[i].then(data => {
                ans[i] = data;
                count++;
                if (count === len) {
                    resolve(ans);
                }
            }, err => {
                reject(err);
            })
        }
    })

}

let p1 = new Promise((reslove, reject) => {
    reslove('p1');
})
let p2 = new Promise((reslove, reject) => {
    reslove('p2');
})
let p3 = new Promise((reslove, reject) => {
    reslove('p3');
})

myAll(p1, p2, p3).then(data => {
    console.log(data)
}, err => {
    console.log(err);
})